package com.solace.wkhtmltopdf.controller;

import com.solace.wkhtmltopdf.httptopdf.HtmlToPdf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * 作者 CG
 * 时间 2020/12/30 11:54
 * 注释 网页转PDF
 */
@RestController
public class PdfController {
    @Autowired
    private HtmlToPdf htmlToPdf;
    @RequestMapping("htmToPdf")
    public String htmToPdf(String url, String filePath) {
        try {
            Process proc = Runtime.getRuntime().exec("wkhtmltopdf "+url+" "+filePath);
            proc.waitFor();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "OK";
    }
    @RequestMapping("htmToImage")
    public String htmToImage(String url, String filePath) {
        htmlToPdf.usageAndExamples(url, filePath);
        return "OK";
    }
    @RequestMapping("usageAndExamples")
    public String usageAndExamples(String url, String filePath) {
        htmlToPdf.usageAndExamples(url, filePath);
        return "OK";
    }

    @RequestMapping("xvfbSupport")
    public String xvfbSupport(String url, String filePath) {
        htmlToPdf.xvfbSupport(url, filePath);
        return "OK";
    }

    @RequestMapping("wkhtmltopdfExitCodes")
    public String wkhtmltopdfExitCodes(String url, String filePath) {
        htmlToPdf.wkhtmltopdfExitCodes(url, filePath);
        return "OK";
    }
}
